﻿@using viBook.Models
@model IEnumerable<Chapter>
@{
    ViewBag.Title = "ListChapters";
    ViewBag.Menu = "Chapter";
    Layout = "~/Views/Shared/_AdminLayout.cshtml";
}
@(Html.Telerik().Grid<Chapter>()
               .Name("list-chapter")
               .DataKeys(keys => keys.Add(c => c.Id))
               .Columns(columns =>
                            {
                                columns.Bound(c => c.Id);
                                columns.Bound(c => c.ChapterName);
                                columns.Bound(c => c.NumberOfPages);
                                columns.Bound(c => c.Id)
                                    .ClientTemplate(string.Format("<a class='t-button' href='javascript:approve(<#= Id #>)'>View</a>"))
                                    .Title("Detail");
                            })
               .DataBinding(dataBinding =>
                                {

                                    dataBinding.Server().Select("ListChapters", "Admins");
                                    dataBinding.Ajax().Select("ListChaptersAjax", "Admins");

                                })

                .Scrollable()
                .Sortable()
                .Pageable()
                .Filterable()
                .Footer(true)

        )
<script type="text/javascript">
    function approve(id) {
        $.ajax({
            url: '@Url.Action("Index", "Chapter")',
            type: 'POST',
            data: { id: id },
            contentType: 'APPLICATION/JSON',
            success: function (result) {
                if (result.success) {

                } else {
                    alert(result.message);
                }
            }
        });
    }
</script>
